package com.czkt.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.czkt.entity.vo.OrdersLineAndOrders;
import com.czkt.entity.vo.OrdersLineProduct;
import lombok.Data;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface ContrRptMapper {
    @Select("SELECT o.odr_customer,SUM(ol.odd_count * ol.odd_price)as odd_price from orders AS o LEFT JOIN orders_line ol ON o.odr_id = ol.odd_order_id GROUP BY o.odr_customer")
    List<OrdersLineAndOrders> ordersLineByOrdersPrice();

    @Select("SELECT o.odr_customer,o.odr_date, SUM(ol.odd_count * ol.odd_price) AS odd_price FROM orders AS o LEFT JOIN  orders_line AS ol ON o.odr_id = ol.odd_order_id WHERE o.odr_date > DATE_SUB(CURDATE(), INTERVAL 2 YEAR) GROUP BY o.odr_customer, YEAR(o.odr_date) ORDER BY  o.odr_customer, odr_date")
    List<OrdersLineAndOrders> ordersLineByOrdersYear();

    @Select("SELECT o.odr_customer,o.odr_date,SUM(ol.odd_count * ol.odd_price) AS odd_price FROM orders AS o LEFT JOIN orders_line AS ol ON o.odr_id = ol.odd_order_id WHERE o.odr_date < DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY o.odr_customer HAVING SUM(ol.odd_count * ol.odd_price) > 0")
    List<OrdersLineAndOrders> ordersLineByYear();

    @Select("SELECT DISTINCT odr_date from orders ORDER BY odr_date")
    List<OrdersLineAndOrders> ordersLineByDate();

    @Select("SELECT DISTINCT odr_customer from orders ORDER BY odr_customer")
    List<OrdersLineAndOrders> ordersLineByCustomer();

    IPage<OrdersLineProduct> ordersLineAndProduct(IPage<OrdersLineProduct> productIPage, @Param("odrCustomer") String odrCustomer,@Param("originDate") String originDate,@Param("finishDate") String finishDate);
}
